<!--
 * Date: 2018年01月02日 09:32:33
 * LastEditors: lvyou
 * LastEditTime: 2019年12月03日 16:47:36
 * FilePath: \youlinweb-master\src\pages\shuohsuo\publishshuoshuo\publishuoshuo.vue
 * copyright(c) 2019-2025 版权为浙江双城网络科技集团有限公司所有，违者必究。
 -->
<template>
  <div>
    <ylheader  @send='sendcomment' :lefttext="true" :lefttexts="'取消'" :title="'发评论'" :righttext="true" :righttexts="'发送'"></ylheader>
    <div>
    <div class="loadmore-container" ref="containerWrapper">
    <div class="loadmore-ul">
      <publishshuoshuo :textareatexts="content" :thumbnailslist="pics"  @haha="textareatext" @commentpics="uploadpics" @changeTextArea="changeTextArea"></publishshuoshuo>
    </div>
    </div>
    </div>
  </div>
</template>
<script>
import ylheader from "src/components/yl-header.vue";
import publishshuoshuo from "src/components/addcomments.vue";
import api from "src/api/index";
import { Indicator } from "mint-ui";
export default {
  name:"publishdis",
  data() {
    return {
      content: "",
      pics: [],
      uploadpictures: [],
      picstring: [],
      caogaoId: "",
      doubleclick: false
    };
  },
  mounted() {

  },
  components: {
    ylheader,
    publishshuoshuo
  },
  methods: {
    //初始化scroll
    initScroll() {
      let p = new Promise((resolve, reject) => {
        this.$nextTick(() => {
          let containerWrapper = this.$refs.containerWrapper;
          this.setScroll(containerWrapper, this);
        });
        resolve("初始化scroll结束...");
      });
      return p;
    },
    setScroll(containerWrapper, _this) {
      localStorage.tempPageHeight = document.getElementsByClassName(
        "loadmore-ul"
      )[0].scrollHeight;
      _this.myscroll = new iScroll(containerWrapper, {
        //上拉时触发
        onScrollMove: function() {
          if (
            this.y <= this.wrapperH - this.scroller.clientHeight - 50 &&
            _this.is_r == false
          ) {
            //加载数据
            _this.is_r = true;
          }
        },
        onScrollEnd: function() {},
        onScrollStart: function() {
          if (
            localStorage.tempPageHeight !=
            document.getElementsByClassName("loadmore-ul")[0].scrollHeight
          ) {
            this.refresh();
            localStorage.tempPageHeight = document.getElementsByClassName(
              "loadmore-ul"
            )[0].scrollHeight;
          }
        }
      });
    },
    textareatext(data) {
      this.content = data;
    },
    uploadpics(data) {
      this.uploadpictures = data;
    },
    sendcomment() {
      if (this.doubleclick) {
        return;
      }
      Indicator.open('发送中...')
      this.doubleclick = true;
      this.uploadpictures = [...this.pics];
      const array = [];
      _each(this.uploadpictures.slice(0, 9), (v, i) => {
        array.push(v.src);
      });
      this.picstring = array.join(",");

      if (!this.content && !this.picstring) {
        this.$toast("请编写评论");
        this.doubleclick = false;
        return;
      }
      //  this.content = this.$util.getTextUrl(this.content);//识别链接
      const comment = {
        circleId: this.$route.query.circleId,
        content: this.content,
        pics: this.picstring,
      };
      if(this.$route.query.beCircleDiscussCommentId){
        comment.beCircleDiscussCommentId = this.$route.query.beCircleDiscussCommentId;
      }
      if(this.$route.query.beCircleDiscussCommentUserId){
        comment.beCircleDiscussCommentUserId = this.$route.query.beCircleDiscussCommentUserId;
      }
      if(this.$route.query.circleDiscussId){
        comment.circleDiscussId = this.$route.query.circleDiscussId; 
        api.Querycirclediscusscommentadd(comment).then(res => {
          if (res.success) {
            this.$router.go(-1);
          } else {
            this.doubleclick = false;
            this.$toast(res.msg);
          }
           Indicator.close()
        });
      }else{
        api.Querycirclediscussadd(comment).then(res => {
          if (res.success) {
            this.$router.go(-1);
          } else {
            this.doubleclick = false;
            this.$toast(res.msg);
          }
           Indicator.close()
        });
      }

    },
    changeTextArea() {
      this.$nextTick(() => {
        this.myscroll.refresh();
      });
    }
  }
};
</script>
<style lang="less" scoped>
.loadmore-container {
  /*height: 95vh;*/
  overflow: hidden;
  margin: 0 auto;
}
.loadmore-ul {
  padding-bottom: 0.2rem;
  list-style: none;
}
</style>
